package cn.xfdzx.android.apps.shop.base;

import android.text.TextUtils;
import android.util.Log;

import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import cn.xfdzx.android.apps.shop.util.LoggerUtil;

public class RequestBase {
    private int page;//页数
    private int limit;//条数


    public int getPages() {
        return page;
    }

    public void setPages(int pages) {
        this.page = pages;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }


    public Map<String, String> getMap() {
        Gson gson = new Gson();
        String json = gson.toJson(this);
        Log.d("TAG", "请求参数"+ json);
        Map<String, String> map = jsonToMap(json);
        return map;
    }

    public static Map<String, String> jsonToMap(String json){
        Map<String, String> map = new HashMap<>();
        try {
            JSONObject jsonObject = new JSONObject(json);
            Iterator<String> it = jsonObject.keys();
            while (it.hasNext()){
                String key = it.next();
                map.put(key, jsonObject.getString(key));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return map;
    }
}
